<?php
/**
 * Fang_DAO_Manager
 * 
 * 作者:  姚刚 (yaogang@the9sense.com)
 * 创建时间: 2011-04-05 18:35:47
 * 修改记录: 
 * 
 * $Id: Manager.php 18 2011-04-17 12:50:07Z coosuu $
 */

class Fang_DAO_Manager extends DAO_Mysql {

    const STATUS_NORMAL = 1;

    const STATUS_REMOVE = 9;

    private static $_table = 'fang_managers';

    /**
     * get 
     * 
     * @param  mixed $mid 
     * @param  array $fields 
     * @return void
     */
    public static function get($mid, $fields = array()) {

        $conditions = 'mid = ?';
        $params = array($mid);
        return parent::getRow(self::$_table, $conditions, $params, $fields);
    }

    /**
     * listAll 
     * 
     * @param  array $pageOptions 
     * @param  array $fields 
     * @return void
     */
    public static function listAll($pageOptions = array(), $fields = array()) {

        return parent::getAll(self::$_table, null, null, $fields, $pageOptions);
    }

    /**
     * getByHandle 
     * 
     * @param  mixed $handle 
     * @param  mixed $fields 
     * @return void
     */
    public static function getByHandle($handle, $fields = array()) {

        $conditions = 'm_handle = ?';
        $params = array($handle);
        return parent::getRow(self::$_table, $conditions, $params, $fields);
    }

    /**
     * add 
     * 
     * @param  mixed $data 
     * @return void
     */
    public static function add($data) {

        if (!$data['m_created']) {
            $data['m_created'] = date('Y-m-d H:i:s');
        }

        if (!$data['m_status']) {
            $data['m_status'] = self::STATUS_NORMAL;
        }

        return parent::add(self::$_table, $data);
    }

    /**
     * update 
     * 
     * @param  mixed $data 
     * @return void
     */
    public static function update($mid, $data) {

        if (!$data['m_updated']) {
            $data['m_updated'] = date('Y-m-d H:i:s');
        }

        return parent::updateByKey(self::$_table, $data, $mid);
    }

    /**
     * count 
     * 
     * @return void
     */
    public static function count() {

        return parent::count(self::$_table);
    }
}
